package org.example.config;

import com.fazecast.jSerialComm.SerialPort;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "printer.usb")
public class SerialPortConfig {
    private String port;
    private int baudRate;
    private int dataBits;
    private int stopBits;
    private int parity;

    @Bean
    public SerialPort serialPort() {
        SerialPort serialPort = SerialPort.getCommPort(port);
        serialPort.setBaudRate(baudRate);
        serialPort.setNumDataBits(dataBits);
        serialPort.setNumStopBits(stopBits);
        serialPort.setParity(parity);
        return serialPort;
    }
}
